import React, { PureComponent } from 'react';
import { Tree } from 'antd';
import { connect } from 'dva';
import "./index.less"
const { TreeNode } = Tree;
class cusPropsTree extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            expandedKeys: [],
            autoExpandParent: true,
            treeData : []
        }
    }
    onSelect() {

    }
    renderTreeNodes = data =>
        data.map(item => {
            if (item.children) {
                return (
                    <TreeNode title={item.title} key={item.key} dataRef={item}>
                        {this.renderTreeNodes(item.children)}
                    </TreeNode>
                );
            }
            return <TreeNode key={item.key} {...item} />;
        });
    onExpand = expandedKeys => {
        console.log('onExpand', expandedKeys);
        this.setState({
            expandedKeys,
            autoExpandParent: false,
        });
    };
    loadData() {
        return new Promise((resolve, reject) => {
            resolve()
        })
    }
    componentDidMount() {
        let {treeData}=this.state;
        this.setState({
            expandedKeys: treeData.map(item => item.key)
        })
    }
    render() {
        let { expandedKeys, autoExpandParent,treeData  } = this.state
        return (
            <Tree
                treeData={treeData}
                onExpand={this.onExpand}
                expandedKeys={expandedKeys}
                autoExpandParent={autoExpandParent}
            >
                {/* {this.renderTreeNodes(treeData)} */}
            </Tree>
        )
    }
}
export default connect(
    ({

    }) => ({

    })
    , dispatch => ({

    }))(cusPropsTree);